#define DEBUG
#include <cstdio>

using namespace std;

const int maxx=39989, maxy=1000000000;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class Line {
public:
  int id;
  double k, b;

  void init(int x0, int y0, int x1, int y1, int id) {
    this->id = id;
    if (x0==x1) {
    } else {
      k = (double)(y1-y0)/(x1-x0);
      b = y0-x0*k;
    }
  }

  double operator()(int x) {
    return k*x+b;
  }
};

class LiChao {
public:
  Line v[4*maxx+1];

  void add(int o, int l, int r, int tl, int tr, Line &tv) {
    int mid=(l+r)/2;
    if (l==tl && r==tr) {
      if (l!=r) {
        if (tv.k>v[o].k) {
          if (tv(mid)>=v[o](mid)) {
            add(o*2, l, mid, l, mid, v[o]);
          } else {
            add(o*2+1, mid+1, r, mid+1, r, tv);
          }
        } else if (tv.k<v[o].k) {
          if (tv(mid)>=v[o](mid)) {
            add(o*2+1, mid+1, r, mid+1, r, v[o]);
          } else {
            add(o*2, l, mid, l, mid, tv);
          }
        }
      }
      if (tv(mid)>=v[o](mid)) {
        v[o] = tv;
      }
    } else {
      if (tl<=mid) {
        add(o*2, l, mid, tl, min(tr, mid), tv);
      }
      if (tr>mid) {
        add(o*2+1, mid+1, r, max(tl, mid+1), tr, tv);
      }
    }
  }

  Line get(int o, int l, int r, int t) {
    if (l==r) {
      return v[o];
    } else {
      Line ret;
      int mid=(l+r)/2;
      if (t<=mid) {
        ret = get(o*2, l, mid, t);
      } else {
        ret = get(o*2+1, mid+1, r, t);
      }
      if (ret(t)<v[o](t)) {
        ret = v[o];
      }
      return ret;
    }
  }
};

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static LiChao tree;
  int n, lastans=0, id=0;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    int opt;
    scanf("%d", &opt);
    if (opt) {
      int x0, y0, x1, y1;
      scanf("%d %d %d %d", &x0, &y0, &x1, &y1);
      x0 = (x0+lastans-1)%maxx+1;
      x1 = (x1+lastans-1)%maxx+1;
      y0 = (y0+lastans-1)%maxy+1;
      y1 = (y1+lastans-1)%maxy+1;
      Line l;
      l.init(x0, y0, x1, y1, ++id);
      tree.add(1, 1, maxx, min(x0, x1), max(x0, x1), l);
    } else {
      int k;
      scanf("%d", &k);
      k = (k+lastans-1)%maxx+1;
      printf("%d\n", lastans=tree.get(1, 1, maxx, k).id);
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
